<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.logging.Level,java.util.logging.Logger" %>
<%@ page import="java.sql.Statement"%>
<%@page import="java.sql.Connection,java.sql.DriverManager" %>
<%@ page import="java.net.URLDecoder" %>

<%
	
	String wanted_movie_src = request.getParameter("wanted_movie_src");
	if (wanted_movie_src != null && wanted_movie_src.length() > 0)
		wanted_movie_src = URLDecoder.decode(wanted_movie_src, "UTF-8");
	
	/*String id = "01";
	String trainNum = "G2314";
	String startStation = "航海";
	String endStation = "滚动";*/
	//wanted_movie_src = "movie_1";
	
	Connection con=null;
	Statement stmt=null;
	ResultSet rs=null;
	int number = 0;
	String driver="com.mysql.cj.jdbc.Driver";
	String url="jdbc:mysql://localhost:3306/android?serverTimezone=GMT&characterEncoding=utf-8";
	String user="root";
	String passwd="HandQuite229";
    try{
       Class.forName(driver);
       con=DriverManager.getConnection(url, user, passwd);
       if (con == null)
      		System.out.println("con is null");
       }catch(ClassNotFoundException e){
           out.println(e);
       }catch(SQLException e){
    	   out.println(e);
       }
	try{
		stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,   
                ResultSet.CONCUR_UPDATABLE);
		String sql = "select * from wanted_movie where id = (select max(id) from wanted_movie)";
		
		System.out.println(sql);
		rs = stmt.executeQuery(sql);
		
		while(rs.next()){
			number = rs.getInt(1);
		}
		System.out.println(number);
		
	}catch (SQLException ex) {
		out.println(ex);
	}

	try{
		stmt=con.createStatement();
		number++;
		String sql2 = "insert into wanted_movie values(" + number + ", '" + wanted_movie_src + "')";
		
		System.out.println(sql2);
		int temp = stmt.executeUpdate(sql2);
		if (temp != 0)
			out.println("true");
		else
			out.println("false");
		
		con.close();
	}catch (SQLException ex) {
		out.println(ex);
	}
%>
